# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libvpx
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.0
pkgrel=1
pkgdesc="The VP8 Codec SDK (mingw-w64)"
arch=('any')
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-yasm")
url="http://www.webmproject.org/"
source=(${_realname}-${pkgver}.tar.gz::https://github.com/webmproject/libvpx/archive/v${pkgver}.tar.gz
        0001-enable-shared-on.mingw.patch
        0002-no-pthreads.mingw.patch
        0003-cross-with-native-binutils.mingw.patch
        0005-fix-exports.mingw.patch
        0009-use-strtok_r.mingw.patch
        0010-Align-thread-entry-point-stack.patch)
options=('strip' 'staticlibs')
sha256sums=('e2fc00c9f60c76f91a1cde16a2356e33a45b76a5a5a1370df65fd57052a4994a'
            '38f1aba2461afd007a6f6a64fdb3eab213bcc279d55b981f77d44209c9c303da'
            'bba4f6f7f18a6c12cef99f5170ff69473049bbb1e7edf1bd83ef8b509d2c6e93'
            'b855c8bbee071dfac267797723ea4ffbb7ebc66d159bc0bb6a64bfee0c08da00'
            '7c511b5df935278da2cba32b03b90582f360ab6786a5e32028bc82025193fabd'
            'd8b602fc6ad9ef7bbd3c239f91c60930b90efee0acab795441051cba4a9bbba4'
            '5a6bc2644b124f37cc86219bfefb046b36721fe642541b96241c49941443c42b')


prepare() {
  cd ${srcdir}/${_realname}-${pkgver}

  patch -Np1 -i ${srcdir}/0001-enable-shared-on.mingw.patch
  patch -Np1 -i ${srcdir}/0002-no-pthreads.mingw.patch
  patch -Np1 -i ${srcdir}/0003-cross-with-native-binutils.mingw.patch
  patch -Np1 -i ${srcdir}/0005-fix-exports.mingw.patch
  patch -Np1 -i ${srcdir}/0009-use-strtok_r.mingw.patch
  patch -Np1 -i ${srcdir}/0010-Align-thread-entry-point-stack.patch
}

build() {
  if [ ${MINGW_CHOST} = "i686-w64-mingw32" ]; then
    _targetarch="x86-win32-gcc"
  else
    _targetarch="x86_64-win64-gcc"
  fi
  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --target=${_targetarch} \
    --enable-vp8 \
    --enable-vp9 \
    --enable-runtime-cpu-detect \
    --enable-postproc \
    --enable-pic \
    --enable-shared \
    --enable-static \
    --enable-experimental \
    --enable-spatial-svc \
    --disable-examples \
    --disable-docs \
    --disable-install-docs \
    --disable-install-srcs

  for _ff in *.mk; do
    sed -i "s/HAVE_GNU_STRIP=yes/HAVE_GNU_STRIP=no/g" $_ff
  done
  make #-j1
}

package() {
  cd "${srcdir}/build-$MINGW_CHOST"
  make DIST_DIR="${pkgdir}${MINGW_PREFIX}" install
}
